package fr.utbm.gi.in56;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import fr.utbm.gi.in56.database.DatabaseManager;

/**
 * Implementation of a debug manager
 *
 * @author Adrien Hoffer & Tarik Belabbas
 *
 */
public class DebugManager extends DatabaseManager
{

	public DebugManager( Connection _connection )
	{
		super( _connection );
	}
	
	public void postAd()
	{
Statement statement = this.getNewStatement();
		
		String user = "Adrien";
		String title = "Mon titre d'annonce";
		title = title.replace( "'", "''" );
		
		
		
		Date date = new Date();
		
		Timestamp tmp = new Timestamp( date.getTime() );
		/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentdate = sdf.format( date );*/
		
		//String sqlQuery = new String("INSERT INTO `date` (`data`) VALUES ('"+currentdate+"')");
		
		//String sqlQuery = new String("INSERT INTO `in56_database`.`ads_buy` (`login_buyer`, `title`, `ad_date`) VALUES ('Adrien', 'mon titre avec espace', '2008-12-06 12:12:12')");
		
		String sqlQuery = new String("INSERT INTO `ads_buy` (`login_buyer`, `title`) VALUES ('" + user +	"', '" + title + "')");
		System.out.println(sqlQuery );
		ResultSet rst = null;
		
		try
		{
			statement.executeUpdate( sqlQuery, Statement.RETURN_GENERATED_KEYS );
			rst = statement.getGeneratedKeys();
			if (rst.next())
			{
		        System.out.println(rst.getInt(1));
			}
			rst.close();
		}
		catch ( SQLException e ){
			e.printStackTrace();
		}
	}

}
